import React, { PureComponent } from 'react';
import { Table, Form, notification } from 'antd';
import { connect } from 'dva';
import "./form.less"
class RoadPoints extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            pagination: {
                pageSize: 5,
                pageNum: 1
            },
            loading: true,
            total: 0,
            data: []
        }
        this.getData = this.getData.bind(this)
        this.paginationChange = this.paginationChange.bind(this)
    }
    async paginationChange(pagination) {
        await this.setState({
            pagination: {
                ...this.state.pagination,
                pageNum: pagination.current
            }
        })
        this.getData()
    }
    async getData() {
        this.setState({
            loading:true
        })
        const {pagination}=this.state;
        let { roadId,type,queryRoadDetail,queryRoadDetail2 } = this.props;
        if(type!=4){
            if (queryRoadDetail) {
                let {res,total} = await queryRoadDetail({...pagination,id:roadId})
                this.setState({
                    loading: false,
                    data: res,
                    total
                })
            }
        }else{
            if (this.props.queryRoadDetail) {
                let {res,total} = await queryRoadDetail2({...pagination,id:roadId})
                this.setState({
                    loading: false,
                    data: res,
                    total
                })
            }
        }
        
    }
    componentDidMount() {
        if (this.props.onLoaded) {
            this.props.onLoaded(this);
        }
        this.getData()

    }
    render() {
        let { type } = this.props;
        const {loading}=this.state;
        let columns;
        if(type==1){
            columns = [
                {
                    title: '序号',
                    render: (text, record, index) => `${index + 1}`,
                },
                {
                    title: '桩号(米)',
                    dataIndex: 'pk',
                    key: 'pk',
                },
                {
                    title: 'pk(坐标)',
                    dataIndex: 'pk',
                    key: 'pk',
                },
                {
                    title: 'z(坐标)',
                    dataIndex: 'z',
                    key: 'z'
                }
            ]
        }else if(type==2){
            columns = [
                {
                    title: '序号',
                    render: (text, record, index) => `${index + 1}`,
                },
                {
                    title: '桩号(米)',
                    dataIndex: 'pk',
                },
                {
                    title: 'pk(坐标)',
                    dataIndex: 'pk',
                },
                {
                    title: 'z0(坐标)',
                    dataIndex: 'z0',
                }
            ]
        }else if(type==3){
            columns = [
                {
                    title: '序号',
                    render: (text, record, index) => `${index + 1}`,
                },
                {
                    title: '桩号(米)',
                    dataIndex: 'pk',

                },
                {
                    title: 'x(坐标)',
                    dataIndex: 'x',

                },
                {
                    title: 'y(坐标)',
                    dataIndex: 'y',

                }
            ]
        }else if(type==4){
            columns = [
                {
                    title: '序号',
                    render: (text, record, index) => `${index + 1}`,
                },
                {
                    title: '桩号(米)',
                    dataIndex: 'pk',
 
                },
                {
                    title: '左横坡(米)',
                    dataIndex: 'leftSlope',
   
                },
                {
                    title: '右横坡(米)',
                    dataIndex: 'rightSlope',
      
                }
            ]
        }
        return (
            <Form>
                <Table onChange={this.paginationChange} pagination={{ 'current': this.state.pagination.pageNum, total: this.state.total }} dataSource={this.state.data} columns={columns}
                    loading={loading}
                    rowKey={record => record.id}>
                </Table>
            </Form>

        )
    }
}
export default connect(
    ({ }) => ({}),
    dispatch => ({
        queryRoadDetail: (params) => dispatch({
            type: 'refRoads/queryRoadDetail',
            payload: params
        }),
        queryRoadDetail2: (params) => dispatch({
            type: 'refRoads/queryRoadDetail2',
            payload: params
        })
    })
)(RoadPoints);